package com.zx.www.volunteersystem.controller;

import com.zx.www.volunteersystem.mapper.UsersMapper;
import com.zx.www.volunteersystem.pojo.Users;
import com.zx.www.volunteersystem.util.R;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class Userscontroller { //http://localhost:8181/user/login

    @Resource
    private UsersMapper usersMapper;
    @PostMapping("/login")
    public R login(@RequestBody Map<String, String> credentials) {
        String username = credentials.get("username");
        String password = credentials.get("password");

        Users user = usersMapper.login(username, password);
        if (user == null) {
            return R.error("用户名或密码错误");
        }
        return R.ok(user);
    }
}
